using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication11.Models.Mapping
{
    public class PatientBasicMap : EntityTypeConfiguration<PatientBasic>
    {
        public PatientBasicMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.Phone)
                .HasMaxLength(50);

            this.Property(t => t.patientId)
                .HasMaxLength(20);

            this.Property(t => t.user_id)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("PatientBasic");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.Sex).HasColumnName("Sex");
            this.Property(t => t.Birthday).HasColumnName("Birthday");
            this.Property(t => t.patientId).HasColumnName("patientId");
            this.Property(t => t.user_id).HasColumnName("user_id");

            // Relationships
            this.HasOptional(t => t.patient)
                .WithMany(t => t.PatientBasics)
                .HasForeignKey(d => d.patientId);
            this.HasOptional(t => t.user)
                .WithMany(t => t.PatientBasics)
                .HasForeignKey(d => d.user_id);

        }
    }
}
